package com.wash.shoes.controller.pc;


import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.domain.R;
import com.wash.shoes.entity.CouponPo;
import com.wash.shoes.service.CouponService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ljg
 * @since 2024-12-01
 */
@Api(tags = {"PC-优惠卷"})
@RestController
@RequestMapping({"/coupon", "/dev-api/coupon"})
public class CouponController {

    @Autowired
    CouponService couponService;

    @ApiOperation("获取优惠卷列表")
    @PostMapping("/list")
    public R<Page<CouponPo>> pageList(@RequestBody CouponPo couponPo) {
        Page<CouponPo> page = couponService.pageList(couponPo);
        return R.ok(page);
    }

    @ApiOperation("修改新增,有id为修改没有为新增")
    @PostMapping("/saveUpdate")
    public R<String> add(@RequestBody CouponPo couponPo) {
        if (ObjectUtil.isEmpty(couponPo.getId())) {
            couponPo.setStatus(2);
            couponService.save(couponPo);
        } else {
            couponService.updateById(couponPo);
        }
        return R.ok();
    }

    @ApiOperation("逻辑删除修改 status为0")
    @PostMapping("/deleteByStatus")
    public R<CouponPo> deleteByStatus(String theId) {

        CouponPo couponPo = couponService.getById(theId);
        couponPo.setStatus(0);
        couponService.updateById(couponPo);
        return R.ok(couponPo);
    }

    @ApiOperation("获取详情")
    @PostMapping("/getDetailById")
    public R<CouponPo> getDetailById(String theId) {
        CouponPo couponPo = couponService.getById(theId);
        return R.ok(couponPo);
    }

}

